<?php 
	$data = empty($data) ? array() : $data; 
?>

<p><?= $this->Html->link("&laquo; Nazad na listu klijenata", "/klijenti", array('escape'=>false)) ?></p>

<?= $this->Form->create("Client", array("url"=>"/klijenti/sacuvaj", "class"=>"entity-form")) ?>
	
	<?= $this->Form->hidden("id", array("value"=>@$data['Client']['id'])) ?>
	
	<?= $this->Form->label('name', 'Naziv Klijenta:') ?>
	<?= $this->Form->text('name', array('value'=>@$data['Client']['name'])) ?>
	
	<?= $this->Form->label('pib', 'PIB:') ?>
	<?= $this->Form->text('pib', array('value'=>@$data['Client']['pib'])) ?>
	
	<?= $this->Form->label('id_number', 'Matični broj:') ?>
	<?= $this->Form->text('id_number', array('value'=>@$data['Client']['id_number'])) ?>
	
	<?= $this->Form->label('account', 'Broj računa:') ?>
	<?= $this->Form->text('account', array('value'=>@$data['Client']['account'])) ?>
	
	<?= $this->Form->label('address', 'Adresa:') ?>
	<?= $this->Form->text('address', array('value'=>@$data['Client']['address'])) ?>
	
    <hr>
        
    <?= $this->Form->label('ClientPayingCurrency.-1.value', 'Nova valuta:') ?>
	<?= $this->Form->text('ClientPayingCurrency.-1.value', array('class'=>'small', 'value'=>@$data['ClientPayingCurrency'][-1]['value'])) ?>
	<?= $this->Form->label('ClientPayingCurrency.-1.effective_date', 'Od:', array('class'=>'auto inline')) ?>
	<?= $this->Form->text('ClientPayingCurrency.-1.effective_date', array('class'=>'datepicker', 'value'=>@$data['ClientPayingCurrency'][-1]['effective_date'])) ?>
    
    <? if(!empty($data['ClientPayingCurrency'])): ?>
	<? unset($data['ClientPayingCurrency'][-1]) ?>
	<br clear="all">
	<div class="label">Valute plaćanja:</div>
	<div class="value list-values">
		<? foreach($data['ClientPayingCurrency'] as $k=>$row): ?>
		<div style="opacity:<?= $k==0 ? 1 : 0.4 ?>">
			<?= $this->Form->hidden("ClientPayingCurrency.{$k}.id", array("value"=>$row['id'])) ?>
			<?= $this->Form->hidden("ClientPayingCurrency.{$k}.value", array("value"=>$row['value'])) ?>
			<?= $this->Form->hidden("ClientPayingCurrency.{$k}.effective_date", array("value"=>$row['effective_date'])) ?>
			<strong><?= $row['value'] ?> dana</strong> (<?= local_date($row['effective_date']) ?>)
			<a class="btn delete" href="javascript:void(0)" onclick="if(confirm('Da li želite da obrišete valutu?')){$(this).parent().remove()}">x</a>
		</div>
		<? endforeach; ?>
	</div>
	<? endif; ?>
	
    <hr>
    
	<?= $this->Form->label('ClientRebate.-1.value', 'Novi Rabat:') ?>
	<?= $this->Form->text('ClientRebate.-1.value', array('class'=>'small', 'value'=>@$data['ClientRebate'][-1]['value'])) ?>
	<?= $this->Form->label('ClientRebate.-1.effective_date', 'Od:', array('class'=>'auto inline')) ?>
	<?= $this->Form->text('ClientRebate.-1.effective_date', array('class'=>'datepicker', 'value'=>@$data['ClientRebate'][-1]['effective_date'])) ?>
	
	<? if(!empty($data['ClientRebate'])): ?>
	<? unset($data['ClientRebate'][-1]) ?>
	<br clear="all">
	<div class="label">Lista Rabata:</div>
	<div class="value list-values">
		<? foreach($data['ClientRebate'] as $k=>$rabat): ?>
		<div style="opacity:<?= $k==0 ? 1 : 0.4 ?>">
			<?= $this->Form->hidden("ClientRebate.{$k}.id", array("value"=>$rabat['id'])) ?>
			<?= $this->Form->hidden("ClientRebate.{$k}.value", array("value"=>$rabat['value'])) ?>
			<?= $this->Form->hidden("ClientRebate.{$k}.effective_date", array("value"=>$rabat['effective_date'])) ?>
			<strong><?= sprintf("%.2f", $rabat['value']) ?>%</strong> (<?= local_date($rabat['effective_date']) ?>)
			<a class="btn delete" href="javascript:void(0)" onclick="if(confirm('Da li želite da obrišete rabat?')){$(this).parent().remove()}">x</a>
		</div>
		<? endforeach; ?>
	</div>
	<? endif; ?>
	
	<?= $this->Form->submit("Sačuvaj", array('div'=>false))?>
<?= $this->Form->end() ?>